unit SetupApi;

interface

uses
  Windows;

const
  // Flags controlling what is included in the device information set built
  // by SetupDiGetClassDevs
  DIGCF_DEFAULT = $00000001; // only valid with DIGCF_DEVICEINTERFACE
  DIGCF_PRESENT = $00000002;
  DIGCF_ALLCLASSES = $00000004;
  DIGCF_PROFILE = $00000008;
  DIGCF_DEVICEINTERFACE = $00000010;
  //
  // Device registry property codes
  // (Codes marked as read-only (R) may only be used for
  // SetupDiGetDeviceRegistryProperty)
  //
  // These values should cover the same set of registry properties
  // as defined by the CM_DRP codes in cfgmgr32.h.
  //
  // Note that SPDRP codes are zero based while CM_DRP codes are one based!
  //
  SPDRP_DEVICEDESC = $00000000;  // DeviceDesc (R/W)
  SPDRP_HARDWAREID = $00000001;  // HardwareID (R/W)
  SPDRP_COMPATIBLEIDS = $00000002;  // CompatibleIDs (R/W)
  SPDRP_UNUSED0 = $00000003;  // unused
  SPDRP_SERVICE = $00000004;  // Service (R/W)
  SPDRP_UNUSED1 = $00000005;  // unused
  SPDRP_UNUSED2 = $00000006;  // unused
  SPDRP_CLASS = $00000007;  // Class (R--tied to ClassGUID)
  SPDRP_CLASSGUID = $00000008;  // ClassGUID (R/W)
  SPDRP_DRIVER = $00000009;  // Driver (R/W)
  SPDRP_CONFIGFLAGS = $0000000A;  // ConfigFlags (R/W)
  SPDRP_MFG = $0000000B;  // Mfg (R/W)
  SPDRP_FRIENDLYNAME = $0000000C;  // FriendlyName (R/W)
  SPDRP_LOCATION_INFORMATION = $0000000D;  // LocationInformation (R/W)
  SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = $0000000E;  // PhysicalDeviceObjectName (R)
  SPDRP_CAPABILITIES = $0000000F;  // Capabilities (R)
  SPDRP_UI_NUMBER = $00000010;  // UiNumber (R)
  SPDRP_UPPERFILTERS = $00000011;  // UpperFilters (R/W)
  SPDRP_LOWERFILTERS = $00000012;  // LowerFilters (R/W)
  SPDRP_BUSTYPEGUID = $00000013;  // BusTypeGUID (R)
  SPDRP_LEGACYBUSTYPE = $00000014;  // LegacyBusType (R)
  SPDRP_BUSNUMBER = $00000015;  // BusNumber (R)
  SPDRP_ENUMERATOR_NAME = $00000016;  // Enumerator Name (R)
  SPDRP_SECURITY = $00000017;  // Security (R/W, binary form)
  SPDRP_SECURITY_SDS = $00000018;  // Security (W, SDS form)
  SPDRP_DEVTYPE = $00000019;  // Device Type (R/W)
  SPDRP_EXCLUSIVE = $0000001A;  // Device is exclusive-access (R/W)
  SPDRP_CHARACTERISTICS = $0000001B;  // Device Characteristics (R/W)
  SPDRP_ADDRESS = $0000001C;  // Device Address (R)
  SPDRP_UI_NUMBER_DESC_FORMAT = $0000001D;  // UiNumberDescFormat (R/W)
  SPDRP_DEVICE_POWER_DATA = $0000001E;  // Device Power Data (R)
  SPDRP_REMOVAL_POLICY = $0000001F;  // Removal Policy (R)
  SPDRP_REMOVAL_POLICY_HW_DEFAULT = $00000020;  // Hardware Removal Policy (R)
  SPDRP_REMOVAL_POLICY_OVERRIDE = $00000021;  // Removal Policy Override (RW)
  SPDRP_INSTALL_STATE = $00000022;  // Device Install State (R)
  SPDRP_LOCATION_PATHS = $00000023;  // Device Location Paths (R)
  SPDRP_BASE_CONTAINERID = $00000024;  // Base ContainerID (R)
  SPDRP_MAXIMUM_PROPERTY = $00000025;  // Upper bound on ordinals
  //
  // Class registry property codes
  // (Codes marked as read-only (R) may only be used for
  // SetupDiGetClassRegistryProperty)
  //
  // These values should cover the same set of registry properties
  // as defined by the CM_CRP codes in cfgmgr32.h.
  // they should also have a 1:1 correspondence with Device registers, where applicable
  // but no overlap otherwise
  //
  SPCRP_UPPERFILTERS = $00000011;  // UpperFilters (R/W)
  SPCRP_LOWERFILTERS = $00000012;  // LowerFilters (R/W)
  SPCRP_SECURITY = $00000017;  // Security (R/W, binary form)
  SPCRP_SECURITY_SDS = $00000018;  // Security (W, SDS form)
  SPCRP_DEVTYPE = $00000019;  // Device Type (R/W)
  SPCRP_EXCLUSIVE = $0000001A;  // Device is exclusive-access (R/W)
  SPCRP_CHARACTERISTICS = $0000001B;  // Device Characteristics (R/W)
  SPCRP_MAXIMUM_PROPERTY = $0000001C;  // Upper bound on ordinals
  //
  // Class installer function codes
  //
  DIF_SELECTDEVICE = $00000001;
  DIF_INSTALLDEVICE = $00000002;
  DIF_ASSIGNRESOURCES = $00000003;
  DIF_PROPERTIES = $00000004;
  DIF_REMOVE = $00000005;
  DIF_FIRSTTIMESETUP = $00000006;
  DIF_FOUNDDEVICE = $00000007;
  DIF_SELECTCLASSDRIVERS = $00000008;
  DIF_VALIDATECLASSDRIVERS = $00000009;
  DIF_INSTALLCLASSDRIVERS = $0000000A;
  DIF_CALCDISKSPACE = $0000000B;
  DIF_DESTROYPRIVATEDATA = $0000000C;
  DIF_VALIDATEDRIVER = $0000000D;
  DIF_DETECT = $0000000F;
  DIF_INSTALLWIZARD = $00000010;
  DIF_DESTROYWIZARDDATA = $00000011;
  DIF_PROPERTYCHANGE = $00000012;
  DIF_ENABLECLASS = $00000013;
  DIF_DETECTVERIFY = $00000014;
  DIF_INSTALLDEVICEFILES = $00000015;
  DIF_UNREMOVE = $00000016;
  DIF_SELECTBESTCOMPATDRV = $00000017;
  DIF_ALLOW_INSTALL = $00000018;
  DIF_REGISTERDEVICE = $00000019;
  DIF_NEWDEVICEWIZARD_PRESELECT = $0000001A;
  DIF_NEWDEVICEWIZARD_SELECT = $0000001B;
  DIF_NEWDEVICEWIZARD_PREANALYZE = $0000001C;
  DIF_NEWDEVICEWIZARD_POSTANALYZE = $0000001D;
  DIF_NEWDEVICEWIZARD_FINISHINSTALL = $0000001E;
  DIF_UNUSED1 = $0000001F;
  DIF_INSTALLINTERFACES = $00000020;
  DIF_DETECTCANCEL = $00000021;
  DIF_REGISTER_COINSTALLERS = $00000022;
  DIF_ADDPROPERTYPAGE_ADVANCED = $00000023;
  DIF_ADDPROPERTYPAGE_BASIC = $00000024;
  DIF_RESERVED1 = $00000025;
  DIF_TROUBLESHOOTER = $00000026;
  DIF_POWERMESSAGEWAKE = $00000027;
  DIF_ADDREMOTEPROPERTYPAGE_ADVANCED = $00000028;
  DIF_UPDATEDRIVER_UI = $00000029;
  DIF_FINISHINSTALL_ACTION = $0000002A;
  DIF_RESERVED2 = $00000030;
  //
  // Values indicating a change in a device's state
  //
  DICS_ENABLE = $00000001;
  DICS_DISABLE = $00000002;
  DICS_PROPCHANGE = $00000003;
  DICS_START = $00000004;
  DICS_STOP = $00000005;
  //
  // Values specifying the scope of a device property change
  //
  DICS_FLAG_GLOBAL = $00000001;  // make change in all hardware profiles
  DICS_FLAG_CONFIGSPECIFIC = $00000002;  // make change in specified profile only
  DICS_FLAG_CONFIGGENERAL = $00000004;  // 1 or more hardware profile-specific

type
  HDEVINFO = type Cardinal;

  DI_FUNCTION = type UINT;

  PSP_DEVINFO_DATA = ^SP_DEVINFO_DATA;

  SP_DEVINFO_DATA = record
    cbSize: DWORD;
    ClassGuid: TGUID;
    DevInst: DWORD;
    Reserved: ULONG_PTR;
  end;

  PSP_CLASSINSTALL_HEADER = ^SP_CLASSINSTALL_HEADER;

  SP_CLASSINSTALL_HEADER = record
    cbSize: DWORD;
    InstallFunction: DI_FUNCTION;
  end;

  PSP_PROPCHANGE_PARAMS = ^SP_PROPCHANGE_PARAMS;

  SP_PROPCHANGE_PARAMS = record
    ClassInstallHeader: SP_CLASSINSTALL_HEADER;
    StateChange: DWORD;
    Scope: DWORD;
    HwProfile: DWORD;
  end;

  PSP_CLASSIMAGELIST_DATA = ^SP_CLASSIMAGELIST_DATA;

  SP_CLASSIMAGELIST_DATA = record
    cbSize: DWORD;
    ImageList: HWND;
    Reserved: DWORD;
  end;

{$IFDEF UNICODE}

function SetupDiGetClassDevs(const ClassGuid: PGUID; Enumerator: PChar; hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall; external 'Setupapi.dll' name 'SetupDiGetClassDevsW';

function SetupDiGetDeviceRegistryProperty(DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; Propertys: DWORD; PropertyRegDataType: PWORD; PropertyBuffer: PByte; PropertyBufferSize: DWORD; RequiredSize: PWORD): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiGetDeviceRegistryPropertyW';

function SetupDiClassNameFromGuid(ClassGuid: PGUID; ClassName: PChar; ClassNameSize: DWORD; RequiredSize: PDWORD): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiClassNameFromGuidW';

function SetupDiSetClassInstallParams(DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; ClassInstallParams: PSP_CLASSINSTALL_HEADER; ClassInstallParamsSize: DWORD): BOOL stdcall; external 'Setupapi.dll' name 'SetupDiSetClassInstallParamsW';
{$ELSE}

function SetupDiGetClassDevs(const ClassGuid: PGUID; Enumerator: PChar; hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall; external 'Setupapi.dll' name 'SetupDiGetClassDevsA';

function SetupDiGetDeviceRegistryProperty(DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; Propertys: DWORD; PropertyRegDataType: PWORD; PropertyBuffer: PByte; PropertyBufferSize: DWORD; RequiredSize: PWORD): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiGetDeviceRegistryPropertyA';

function SetupDiClassNameFromGuid(ClassGuid: PGUID; ClassName: PChar; ClassNameSize: DWORD; RequiredSize: PDWORD): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiClassNameFromGuidA';

function SetupDiSetClassInstallParams(DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA; ClassInstallParams: PSP_CLASSINSTALL_HEADER; ClassInstallParamsSize: DWORD): BOOL stdcall; external 'Setupapi.dll' name 'SetupDiSetClassInstallParamsA';
{$ENDIF}

function SetupDiEnumDeviceInfo(DeviceInfoSet: HDEVINFO; MemberIndex: DWORD; DeviceInfoData: PSP_DEVINFO_DATA): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiEnumDeviceInfo';

function SetupDiDestroyDeviceInfoList(DeviceInfoSet: HDEVINFO): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiDestroyDeviceInfoList';

function SetupDiCallClassInstaller(InstallFunction: DI_FUNCTION; DeviceInfoSet: HDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiCallClassInstaller';

function SetupDiGetClassImageList(ClassImageListData: PSP_CLASSIMAGELIST_DATA): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiGetClassImageList';

function SetupDiDestroyClassImageList(ClassImageListData: PSP_CLASSIMAGELIST_DATA): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiDestroyClassImageList';

function SetupDiGetClassImageIndex(ClassImageListData: PSP_CLASSIMAGELIST_DATA; ClassGuid: PGUID; ImageIndex: PINT): BOOL; stdcall; external 'Setupapi.dll' name 'SetupDiGetClassImageIndex';

implementation

end.

